package com.openthinks.joyniproject.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.openthinks.joyniproject.dao.AccountDao;
import com.openthinks.joyniproject.dao.BaseDao;
import com.openthinks.joyniproject.model.UserInfo;
import com.openthinks.joyniproject.utils.SQLConfigLoader;
@Repository
public class AccountDaoImpl implements AccountDao{
	@Autowired
	private BaseDao baseDao;
	
	private static Logger logger = Logger.getLogger(AccountDaoImpl.class);

	@Override
	public UserInfo get(UserInfo userInfo) {
		String sql = SQLConfigLoader.getSQL("Account.userLogin");

		Map<String,Object> paramMap = new HashMap<String,Object>();
		paramMap.put("longinName",userInfo.getLoginName());
		paramMap.put("password",userInfo.getPassword());

		return this.baseDao.queryForObject(sql, UserInfo.class, paramMap);
	}
	
	@Override
	public List<UserInfo> getUserInfoByIds(List<String> ids) {
		String sql = SQLConfigLoader.getSQL("Account.queryUserInfoByIds");

		Map<String, Object> paramMap = new HashMap<String,Object>();
		paramMap.put("ids",ids);
		
		List<UserInfo> result = baseDao.queryObjectForList(sql, UserInfo.class,paramMap);
		
		return result;
	}
	
	public boolean changePassword(Map<String,Object> data){
		String sql = SQLConfigLoader.getSQL("Account.changePassword");
		 
		return this.baseDao.update(sql, data);
	}
	
	public UserInfo getUserInfoById(long id){
		String sql=SQLConfigLoader.getSQL("Account.queryUserInfoById");
		Map<String, Object> paramMap = new HashMap<String,Object>();
		paramMap.put("id",id);
		return this.baseDao.queryForObject(sql, UserInfo.class, paramMap);
	}
	
	@Override
	public List<UserInfo> getUserInfoByDeptId(String deptId) {
		
		String sql=SQLConfigLoader.getSQL("Account.queryUserInfoByDeptId");
		Map<String, Object> paramMap = new HashMap<String,Object>();
		paramMap.put("deptId", deptId);
		List<UserInfo> result = baseDao.queryObjectForList(sql, UserInfo.class,paramMap);
		
		return result;
	}
}
